//
//  ZYRuntime.m
//  OC_Principle
//
//  Created by wangzhipan on 2025/2/11.
//

#import "ZYRuntime.h"
#import <objc/runtime.h>

@implementation ZYRuntime

void run(id self, SEL _cmd)
{
    NSLog(@"ZYRuntime -%s", __func__);
}

void setId(id self, SEL _cmd, int _id)
{
    NSLog(@"ZYRuntime  +%s  id==%d", __func__,_id);
}

+ (BOOL)resolveInstanceMethod:(SEL)sel
{
    if (sel == @selector(run)) {
        class_addMethod(self, sel, (void *)run, "v@:");
        return YES;
    }
    return [super resolveInstanceMethod:sel];
}

+ (BOOL)resolveClassMethod:(SEL)sel
{
    if (sel == @selector(setId:)) {
        class_addMethod(object_getClass(self), @selector(setId:), (void *)setId, "v@:i");
        return YES;
    }
    return [super resolveClassMethod:sel];
}

@end
